$(function () {
  // fullpage动画效果设置

  function AddClass1() {
    $('.vatilText1').eq(0).removeClass('vatilActive1');
    $('.vatilImg1').eq(0).removeClass('ImgActive1');
    $('.content1').eq(0).removeClass('contentActive1');
    setTimeout(() => {
      $('.vatilText1').eq(0).addClass('vatilActive1');
      $('.vatilImg1').eq(0).addClass('ImgActive1');
      $('.content1').eq(0).addClass('contentActive1');
    }, 100)
  }
  function AddClass2() {
    $('.vatilText2').removeClass('vatilActive2');
    $('.vatilImg2').removeClass('ImgActive2');
    $('.content2').removeClass('contentActive2');
    setTimeout(() => {
      $('.vatilText2').addClass('vatilActive2');
      $('.vatilImg2').addClass('ImgActive2');
      $('.content2').addClass('contentActive2');
    }, 100);
  }
  function AddClass3() {
    $('.vatilText3').removeClass('vatilActive3');
    $('.vatilImg3').removeClass('ImgActive3');
    $('.content3').removeClass('contentActive3');
    setTimeout(() => {
      $('.vatilText3').addClass('vatilActive3');
      $('.vatilImg3').addClass('ImgActive3');
      $('.content3').addClass('contentActive3');
    }, 100);
  }
  function AddClass4() {
    $('.yearTop').removeClass('userMessActive');
    $('.left').removeClass('leftActive');
    $('.right').removeClass('rightActive');
    $('.backBtn').removeClass('backBtnActive')
    setTimeout(() => {
      $('.yearTop').addClass('userMessActive');
      $('.left').addClass('leftActive');
      $('.right').addClass('rightActive');
      $('.backBtn').addClass('backBtnActive')
    }, 100);
  }
  // 3.调用插件fullpage方法
  $(".pageAll").fullpage({
    //导航小圆点(在右侧)
    navigation: false,
    verticalCentered: true,
    css3: true,
    easing: 'easeOutBounce',
    afterSlideLoad: function (anchorLink, index, slideAnchor, slideIndex) {
      // console.log('滚屏');
    },
    //sections的颜色,s不要漏了
    // sectionsColor: ["-webkit-gradient(linear,left top,left bottom,from(#9acd32),to(#ffa500))", "#9acd32", "#ffa500", "#008000", "#87ceeb"],
    //进入某一屏会调用的函数(其中参数a不用,index代表第几屏,index从1开始)
    afterLoad: function (a, index) {
      // console.log('滚屏后');
      $('.titleh1').eq(0).addClass('titlehActive');
      $('.userbg').eq(0).addClass('userActive');
      $('.lookBtn').eq(0).addClass('lookBtnActive');
    },
    //离开某一屏会调用的函数(其中参数a,b不用)
    onLeave: function (index, nextIndex, direction) {
      // console.log('滚屏前');
      // 三个参数分别代表当前页面，和跳转的页面，最后是切换的方向
      // $('.vatilText1').eq(0).removeClass('vatilActive1');
      // $('.vatilImg1').eq(0).removeClass('ImgActive1');
      // $('.content1').eq(0).removeClass('contentActive1');
      // console.log(index)
      if (index == 1) {
        AddClass1()
        // 离开第二页进入第三页，添加leaved类名，并有回调函数
      }
      if (index == 2) {
        $('.titleh1').eq(0).removeClass('titlehActive');
        $('.userbg').eq(0).removeClass('userActive');
        $('.lookBtn').eq(0).removeClass('lookBtnActive');
        setTimeout(() => {
          $('.titleh1').eq(0).addClass('titlehActive');
          $('.userbg').eq(0).addClass('userActive');
          $('.lookBtn').eq(0).addClass('lookBtnActive');
        }, 100);
        AddClass2()
      }
      if (index == 3) {
        AddClass1()
        AddClass2()
        AddClass3()
      }
      if (index == 4) {
        AddClass2()
        AddClass3()
      }
      if (index == 5 || index == 6 || index == 7 || index == 8) {
        AddClass2()
        AddClass3()
      }
      if (index == 9 || index == 10) {
        AddClass2()
        AddClass3()
        AddClass4()
      }
    },
    css3: true,
    afterRender: function () {

    }
  });
  //  $.fn.fullpage.moveSectionDown();//向下滚动一页
  /*前往正文页面=>立即查看*/
  $('.page-1 .button').one('click',function () {
    $.fn.fullpage.moveSectionDown();
    $('.section').hover(function () {
      clearInterval(TimeOut)
    }, function () {
      TimeOut = setInterval(function () {
        $.fn.fullpage.moveSectionDown();
      }, 3000);
    })
  });
  /*回顶部=>重温TA的2017*/
  $('.page-10 .button').click(function () {
    $.fn.fullpage.moveTo(1, 0);
  });


/**
 * json数据对接
 */
var user_no = '133607';
$(document).ready(function () {
    var jsonData = getJsonData(user_no);
    // console.log('jsonData',jsonData);
    let summaryLeft = document.getElementById('summaryLeft');
    let summaryRight = document.getElementById('summaryRight');
    let Things = [];
    let annualFunParents = [];
    let userRank = '';
    // 调查问卷的
    // http://mes.abu.com:9000//AnnualSummary/AnnualSummary.asmx/InsertAnnualContent?user_no=string&content=string&opinion=string
    var url = "demo.json"/*json文件url，本地的就写本地的位置，如果是服务器的就写服务器的路径*/
    var res = JSON.parse(jsonData);
    console.log(res)
    loginDate = res.LoginDateSfc;
    LoginTimeFirst = res.LoginTimeSfcFirst;
    LoginTimeFirst1 = LoginTimeFirst.split(' ');
    LoginTimeFirst2 = LoginTimeFirst1[0].split('-');
    LoginTimeLast = res.LoginTimeSfcLast;
    LoginTimeLast1 = LoginTimeLast.split(' ');
    LoginTimeLast2 = LoginTimeLast1[0].split('-')
    lastDay = res.LastDaySfc;
    lastDay1 = lastDay.split(' ');
    lastDay2 = lastDay1[0].split('-');
    totalDay = res.DaySfc;
    totalClick = res.TotalClickSfc;
    totalDay1 = loginDate.split(' ');
    totalDay2 = totalDay1[0].split('-');
    userRank = res.UserPositionSfc;
    userProportion = res.UserProportionSfc;
    annualFunParents = res.annualFunParentSfcs;
    userName = res.UserName;
    timeMost = res.LoginTimeFavSfc;
    Things = res.annualFunSfcs;
    $('.early').text(LoginTimeFirst1[1]);
    $('.early2').text(LoginTimeFirst2[0] + "." + LoginTimeFirst2[1] + "." + LoginTimeFirst2[2]);
    $('.latest').text(LoginTimeLast1[1]);
    $('.latest2').text(LoginTimeLast2[0] + "." + LoginTimeLast2[1] + "." + LoginTimeLast2[2]);
    $('.userMess').text(userName);
    $('#fday').text(totalDay2[0] + '年' + totalDay2[1] + '月' + totalDay2[2] + '日');
    $('#firstDay').text(totalDay2[0] + '.' + totalDay2[1] + '.' + totalDay2[2] + '.' + ' ' + totalDay1[1]);
    $('.lastDay').text(lastDay2[0] + '年' + lastDay2[1] + '月' + lastDay2[2] + '日');
    $('.lastDay2').text(lastDay2[0] + '.' + lastDay2[1] + '.' + lastDay2[2] + '.' + ' ' + lastDay1[1]);
    $('.totalDay').text(totalDay);
    $('.timeMost').text(timeMost);
    $('.userProportion').text(userProportion);
    $('.userRank').text("Top"+userRank);
    getSummary();
    getMostBrowse();
    function getMostBrowse() {
        let thingsName = [];
        let thingsClick = [];
        let mostBrowse = 0;
        console.log('Things'+Things);
            for (let i = 0; i < Things.length; i++) {
                thingsName1 = Things[0].FunName;
                thingsName = thingsName1.split('.')[0]
                thingsClick = Things[i].ClickCount;
                mostBrowse += parseInt(thingsClick);
            }
        $('.mostBrowse').text(mostBrowse);
        $('.mostList').text(thingsName);
    }
    function getSummary() {
        let annualName = [];
        let annualClick = [];
        let str1 = '';
        let str2 = '';
        if (annualFunParents.length < 10 && annualFunParents.length > 0) {
            for (let j = 0; j < annualFunParents.length; j++) {
                annualName1 = annualFunParents[j].FunName;
                annualName = annualName1.split('.')[0];
                annualClick = annualFunParents[j].ClickCount;
                str1 += `<p>${annualName}</p>`
                str2 += `<p>${annualClick}</p>`
            }
            summaryLeft.innerHTML = str1;
            summaryRight.innerHTML = str2;
        } else if (annualFunParents.length === 0) {
            str1 += '';
            str2 += '';
            summaryLeft.innerHTML = '';
            summaryRight.innerHTML = '';
        } else {
            for (let j = 0; j < 10; j++) {
                annualName1 = annualFunParents[j].FunName;
                annualName = annualName1.split('.')[0];
                annualClick = annualFunParents[j].ClickCount;
                str1 += `<p>${annualName}</p>`
                str2 += `<p>${annualClick}</p>`
            }
            summaryLeft.innerHTML = str1;
            summaryRight.innerHTML = str2;
        }
    }
})
 function getQueryVariable(variable) {
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i = 0; i < vars.length; i++) {
            var pair = vars[i].split("=");
            if (pair[0] == variable) { return pair[1]; }
        }
 }


function urlHtml(params) {
  //获取url地址
  var ts_href = window.location.href;
  var ts_mainText="";
  if(params==1){
    //获取地址最后一个“/”的下标
    var ts_indexof = ts_href.lastIndexOf("/");
    //获取地址“/”之后的的内容
    var ts_indexText = ts_href.substring(ts_indexof + 1);
    //获取地址“.html”的下标
    var ts_htmlBeforeText = ts_indexText.indexOf(".html");
    //获取 “/”到".html"之间的内容
    ts_mainText = ts_indexText.substring(0, ts_htmlBeforeText);
  }else if(params==2){
    //获取地址“/”的下标
    var ts_indexof = ts_href.lastIndexOf("/");
    //获取地址“/”之后的的内容
    var ts_indexText = ts_href.substring(ts_indexof + 1);
    ts_mainText = ts_indexText;
  }else if(params==3){
    //获取地址中倒数二个“/”下标的位置的之后的内容
    var urlParents=ts_href.substr(ts_href.lastIndexOf('/', ts_href.lastIndexOf('/') - 1) + 1);
    ts_mainText=urlParents
  }else if(params==4){
    //获取地址中倒数二个“/”的下标之后的内容
    var urlParents=ts_href.substr(ts_href.lastIndexOf('/', ts_href.lastIndexOf('/') - 1) + 1);
    //取到倒数二个“/”的下标的位置和.html之间的内容
    var beforeHtml = urlParents.indexOf(".html");
    if(beforeHtml==-1){
      ts_mainText=urlParents;
      
    }else{
      ts_mainText=urlParents.substring(0, beforeHtml);
    }
  }else{
    var urlParents=ts_href.substr(ts_href.lastIndexOf('/', ts_href.lastIndexOf('/') - 1) + 1);
    var beforeHtml = urlParents.indexOf(".html");
    if(beforeHtml==-1){
      ts_mainText=urlParents;
      
    }else{
      ts_mainText=urlParents.substring(0, beforeHtml);
    }
  }
  return ts_mainText;
}

})
